<?php
/**
 * --------------------------------------------------------------
 * 管理员验证器
 * --------------------------------------------------------------
 * Light Year Doc
 * @author yinq<3331653644@qq.com>
 * --------------------------------------------------------------
 */
namespace app\admin\validate;

use think\Validate;

class Admin extends Validate
{
    // 定义验证规则
    protected $rule = [
        'adminname' => 'unique:admin|require|alphaDash|length:3,15',
        'password'  => 'require|alphaDash|length:6,20',
        'email'     => 'require|email|unique:admin',
        'verify'    => 'require|captcha',
    ];
    // 定义验证提示
    protected $message = [
        'adminname.unique'    => '用户名已经存在！',
        'adminname.require'   => '用户名不能为空！',
        'adminname.alphaDash' => '用户名格式不正确！',
        'adminname.length'    => '用户名长度3-15位！',
        'password.require'    => '密码不能为空！',
        'password.length'     => '密码长度6-20位！',
        'email.require'       => '邮箱不能为空！',
        'email.email'         => '邮箱地址有误！',
        'email.unique'        => '该邮箱已存在',
        'verify.require'      => '验证码不能为空！',
        'verify.captcha'      => '验证码错误！'
    ];
    
    // 定义验证场景
    protected $scene = [
        // 修改个人信息
        'edit'    => ['email'],
        // 登录
        'login'   => ['adminname' => 'require', 'password' => 'require', 'verify'],
		// 新增
		'add'     => ['adminname', 'password', 'email'],
        // 修改密码
        'editpwd' => [
            'oldpassword|旧的密码' => 'require',
            'newpassword|新的密码' => 'require|alphaDash|length:6,20',
            'repassword|确认密码'  => 'require|alphaDash|length:6,20|confirm:newpassword'
        ]
    ];
}